/*
 * ChooseBankCardFragment.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.shoppingcart.choosebankcard;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.yidiandao.business.R;
import com.yidiandao.business.base.BaseFragment;
import com.yidiandao.business.ui.adapter.ChooseBankCardAdapter;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

public class ChooseBankCardFragment extends BaseFragment
        implements ChooseBankCardContract.View, View.OnClickListener {

    private ChooseBankCardContract.Presenter mPresenter;

    private Toolbar mToolbar;

    private ListView mListView;

    private Button mBtnUserNewCardToPay;

    private ChooseBankCardAdapter mAdapter;

    public static ChooseBankCardFragment getInstance() {
        ChooseBankCardFragment fragment = new ChooseBankCardFragment();
        return fragment;
    }

    @Override
    public void setPresenter(ChooseBankCardContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return ChooseBankCardFragment.class.getSimpleName();
    }

    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }

    @Override
    protected void initViews() {
        mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        mListView = (ListView) mRootView.findViewById(R.id.list_view);
        mBtnUserNewCardToPay = (Button) mRootView.findViewById(R.id.btn_use_new_card_to_pay);

        initListView();
        initListeners();

        mPresenter.start();
    }

    private void initListView() {
        mAdapter = new ChooseBankCardAdapter(mActivity);
        mListView.setAdapter(mAdapter);
    }

    private void initListeners() {
        mToolbar.setNavigationOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mActivity.finish();
                    }
                });

        mBtnUserNewCardToPay.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_choose_bank_card;
    }

    @Override
    public void setDisplayListItems(List<DisplayListItem> displayListItems) {
        mAdapter.setData(displayListItems);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_use_new_card_to_pay:
                // 选择新卡支付
                break;
        }
    }
}
